from django.shortcuts import render
from polls import models
import json
import MySQLdb
from django.core import serializers
from django.http import JsonResponse
from django.shortcuts import HttpResponse
# Create your views here.
from django.http import HttpResponse
from django.shortcuts import HttpResponseRedirect
import socket

def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

	
def recieve_data(request):
	
	'''if request.method == 'GET':
		response = {}
		OpenID = int(request.GET.get('OpenID'))
		print(type(OpenID))
		humidity_selected = models.humidity_temperature.objects.filter(light=OpenID)
		humidity= json.loads(serializers.serialize("json", humidity_selected))
		print(humidity)
		if len(humidity) == 0:
			response['Msg'] = 'error'
			response['StatusCode'] = 1
		else:
			response['Msg'][0] = humidity[0]['fields']
			response['StatusCode'] = 0
		return JsonResponse(response)'''
		
	tables = models.humidity_temperature.objects.all()	
	length = len(tables)
	tables = tables[length-1:length]
	#print(length)
	#tables = json.loads(serializers.serialize("json", table))
	return render(request,"table.html",locals())